package no.ntnu.fp.model;

import no.ntnu.fp.gui.EventDispatcher;
import no.ntnu.fp.model.events.EmployeeChangedEvent;
import no.ntnu.fp.model.events.LoggedInChangedEvent;

public class LoggedInModel {
	private boolean loggedIn;
	private Employee employee;

	public enum LoginError {
		ALREADY_LOGGED_IN, INVALID_USER_CREDENTIALS;
	}
	
	public LoggedInModel(){
		loggedIn = false;
	}
	public synchronized Employee getEmployee(){
		return employee;
	}
	public synchronized void setLoggedIn(boolean loggedIn, LoginError error) {
		LoggedInChangedEvent evt = new LoggedInChangedEvent(this, this.loggedIn, 
															loggedIn, error);
		this.loggedIn = loggedIn;

		EventDispatcher.dispatchEvent(evt);
	}
	public synchronized void setEmployee(Employee employee) {
		EmployeeChangedEvent evt = new EmployeeChangedEvent(this, this.employee, employee);
		this.employee = employee;
		EventDispatcher.dispatchEvent(evt);
	}
}
